<?php
  // $x=$_GET["val0"];
  // $y=$_GET["val1"];
 //  echo $x+$y;

$con = mysql_connect("localhost","shawnvision7264","abcde56789");
//$con = mysql_connect("localhost","root","");
if (!$con)
{
    die('Could not connect: ' . mysql_error());
}
else
{
   //echo  ("connect success");
//   mysql_select_db("test", $con);   //for local database in LVX
    mysql_select_db("shawnvision7264", $con);

    $result = mysql_query("SELECT * FROM devstoretable");
    $num_rows = mysql_num_rows($result);
   // echo  ("<br>Count in whole Table devstoretable ");
   // echo (  $num_rows);
   // echo ( "<br>");


    //According to the dev count in the table, we echo the signal.
    //"F"  means  Full, we can not add more machines. 
    //"I"  means  insert.
    //"H"  means the dev name already in the table.

    if($num_rows>58)
    {
        echo ( "F");
    }
    else
    {
        $x=$_GET["Name"];
        $result = mysql_query("SELECT * FROM devstoretable  WHERE DevName=$x");
        //echo  ("<br>Count in whole Table devstoretable for name== $x ");

        $num_rows1 = mysql_num_rows($result);
        //echo (  $num_rows1);
          if(  $num_rows1>0 )
          {
              $devCount=mysql_query("SELECT ConnCount FROM devstoretable  WHERE DevName=$x");

              echo ("H");
              while($row = mysql_fetch_array($devCount))
              {
                 // echo $row['ConnCount'];

                  $devCount0=$row['ConnCount'];
                  $devCount0=$devCount0+1;
                  mysql_query("UPDATE devstoretable SET ConnCount = $devCount0 WHERE DevName = $x");

                 // echo "<br />";
              }
          }
          else
          {
              mysql_query("INSERT INTO devstoretable (DevName, ConnCount ) 
                    VALUES ($x, 1)");

              echo ("I");
          }


        //  echo ( "<br>");

    }

  }

// some code

 ?>

